package com.ruoyi.web.controller.mes;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageHelper;
import com.ruoyi.web.domain.MesUseInfo;
import com.ruoyi.web.domain.Placrorder.Setupinfo2;
import com.ruoyi.web.domain.vo.MesUseDetailVo;
import com.ruoyi.web.domain.vo.RefundDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.MesRefundInfo;
import com.ruoyi.web.service.IMesRefundInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退库单Controller
 * 
 * @author wxt
 * @date 2024-01-23
 */
@Api("纸张退库单管理")
@RestController
@RequestMapping("/mes/refund/info")
public class MesRefundInfoController extends BaseController
{
    @Autowired
    private IMesRefundInfoService mesRefundInfoService;

    /**
     * 查询退库单列表
     */
    @ApiOperation("查询退库单列表")
    @GetMapping("/list")
    public TableDataInfo list(MesRefundInfo mesRefundInfo)
    {
        startPage();
        List<MesRefundInfo> list = mesRefundInfoService.selectMesRefundInfoList(mesRefundInfo);
        return getDataTable(list);
    }

    /**
     * 导出退库单列表
     */
    @ApiOperation("导出退库单列表")
    @Log(title = "退库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(HttpServletResponse response, MesRefundInfo mesRefundInfo)
    {
        List<MesRefundInfo> list = mesRefundInfoService.selectMesRefundInfoList(mesRefundInfo);
        ExcelUtil<MesRefundInfo> util = new ExcelUtil<MesRefundInfo>(MesRefundInfo.class);
        //util.exportExcel(response, list, "退库单数据");
        return  util.exportExcel(list, "退库单数据");
    }

    /**
     * 获取退库单详细信息
     */
    @ApiOperation("获取退库单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesRefundInfoService.selectMesRefundInfoById(id));
    }


    /**
     * 纸张退库明细查询
     */
    @ApiOperation("纸张退库明细查询")
    @PostMapping("/Detail")
    public TableDataInfo Detail(@RequestBody Map<String,Object> params)
    {
        //startPage();
        PageHelper.startPage((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
        MesRefundInfo use=new MesRefundInfo();
        use.setParams(params);
        List<RefundDetailVo> list = mesRefundInfoService.selectMesDetaillist(use);
        return getDataTable(list);
    }

    /**
     * 新增退库单
     */
    @ApiOperation("新增退库单")
    @Log(title = "退库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesRefundInfo mesRefundInfo)
    {
        return toAjax(mesRefundInfoService.insertMesRefundInfo(mesRefundInfo));
    }

    /**
     * 修改退库单
     */
    @ApiOperation("修改退库单")
    @Log(title = "退库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesRefundInfo mesRefundInfo)
    {
        return toAjax(mesRefundInfoService.updateMesRefundInfo(mesRefundInfo));
    }

    /**
     * 删除退库单
     */
    @ApiOperation("删除退库单")
    @Log(title = "退库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesRefundInfoService.deleteMesRefundInfoByIds(ids));
    }
}
